package util;

import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;

import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;


public class AutoScreenShot {
	private WebDriver w;
	private String s = "D:\\IntelliJ_workplace\\ErrorShot\\";
	public static AutoScreenShot autoScreenShot = new AutoScreenShot();
	public static AutoScreenShot getInstance(){
		return autoScreenShot;
	}

	public static int t = 1;
	public static String getDateTime(){
		SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd_HHmmss");
		return df.format(new Date());
	}
	
//	public static void ScreenShot(WebDriver w, String s){
//		File screenshot = ((TakesScreenshot)w).getScreenshotAs(OutputType.FILE);
//		try {
//			FileUtils.copyFile(screenshot, new File(s+getDateTime()+"_"+t+".jpg"));
//			++t;
//		} catch (IOException e) {
//			// TODO: handle exception
//			e.printStackTrace();
//		}
//
//	}

	public static void ScreenShot(){
		File screenshot = ((TakesScreenshot)autoScreenShot.w).getScreenshotAs(OutputType.FILE);
		try {
			FileUtils.copyFile(screenshot, new File(autoScreenShot.s+getDateTime()+"_"+t+".jpg"));
			++t;
		} catch (IOException e) {
			// TODO: handle exception
			e.printStackTrace();
		}

	}

	public  void setDriverInScreenShot(WebDriver w){
		autoScreenShot.w = w;

	}

}
